import { getLevelFirst, getLevelZero, getUserID } from '@/utils';

/** 采购申请Manage数据范围权限判断 */
const ApplyManageTab = (curRes: Record<string, any>) => {
  if (curRes?.['/purchaseApplyController/applyCompanyID']) {
    return {
      applyCompanyID: getLevelZero(),
      params: 'applyCompanyID',
      key: 'ApplyManageTabKey',
    };
  } else if (curRes?.['/purchaseApplyController/applyDepartmentID']) {
    return {
      applyDepartmentID: getLevelFirst(),
      params: 'applyDepartmentID',
      key: 'ApplyManageTabKey',
    };
  } else if (curRes?.['/purchaseApplyController/applyerID']) {
    return {
      applyerID: getUserID(),
      params: 'applyerID',
      key: 'ApplyManageTabKey',
    };
  } else {
    return {};
  }
};

/** 采购计划Manage数据范围权限判断 */
const PlanManageTab = (curRes: Record<string, any>) => {
  if (curRes?.['/purchasePlanController/applyCompanyID']) {
    // 公司权限
    return {
      params: 'applyCompanyID',
      applyCompanyID: getLevelZero(),
    };
  } else if (curRes?.['/purchasePlanController/applyDepartmentID']) {
    return {
      params: 'applyDepartmentID',
      applyDepartmentID: getLevelFirst(),
    };
  } else if (curRes?.['/purchasePlanController/applyerID']) {
    return {
      params: 'applyerID',
      applyerID: getUserID(),
    };
  }
};

const ApplyManageTabSwitch = (curRes: Record<string, any>) => {
  const ApplyManageTab = () => {
    if (curRes?.['/purchaseApplyController/createCompanyID']) {
      return {
        createCompanyID: getLevelZero(),
        params: 'createCompanyID',
        key: 'ApplyManageTabKey',
      };
    } else if (curRes?.['/purchaseApplyController/createDepartmentID']) {
      return {
        createDepartmentID: getLevelFirst(),
        params: 'createDepartmentID',
        key: 'ApplyManageTabKey',
      };
    } else if (curRes?.['/purchaseApplyController/createrID']) {
      return {
        createrID: getUserID(),
        params: 'createrID',
        key: 'ApplyManageTabKey',
      };
    }
  };

  const ApplyCheckTab = () => {
    if (curRes?.['/needController/getMyCheck']) {
      return {
        createDepartmentID: getLevelFirst(),
        params: 'createDepartmentID',
        key: 'NeedCheckTabKey',
        state: 2,
      };
    }
  };

  return [
    {
      title: '申请管理',
      key: 'ApplyManageTabKey',
      visible:
        (curRes?.['/purchaseApplyController/createCompanyID'] ||
          curRes?.['/purchaseApplyController/createDepartmentID'] ||
          curRes?.['/purchaseApplyController/createrID']) ??
        false,
      md: 2,
      sm: 24,
      params: ApplyManageTab(),
    },
    {
      title: '我的审核',
      key: 'ApplyCheckTabKey',
      visible: curRes?.['/purchaseApplyController/myApplyCheck'] ?? false,
      md: 2,
      sm: 24,
      params: ApplyCheckTab(),
    },
  ];
};

export { ApplyManageTabSwitch, ApplyManageTab, PlanManageTab };

export const ApplyTabSwitch = (curRes) => {
  if (curRes?.['/purchaseApplyController/createCompanyID']) {
    return {
      createCompanyID: getLevelZero(),
      params: 'createCompanyID',
      key: 'ApplyManageTabKey',
    };
  } else if (curRes?.['/purchaseApplyController/createDepartmentID']) {
    return {
      createDepartmentID: getLevelFirst(),
      params: 'createDepartmentID',
      key: 'ApplyManageTabKey',
    };
  } else if (curRes?.['/purchaseApplyController/createrID']) {
    return {
      createrID: getUserID(),
      params: 'createrID',
      key: 'ApplyManageTabKey',
    };
  }
};

export const NeedMaterialTabSwitch: any = (curRes: Record<string, any>) => {
  if (curRes?.['/purchaseNeedMaterialController/ownCompanyID']) {
    return {
      params: 'ownCompanyID',
      ownCompanyID: getLevelZero(),
    };
  } else if (curRes?.['/purchaseNeedMaterialController/ownDepartmentID']) {
    return {
      params: 'ownDepartmentID',
      ownDepartmentID: getLevelFirst(),
    };
  } else if (curRes?.['/purchaseNeedMaterialController/ownerID']) {
    return {
      params: 'ownerID',
      ownerID: getUserID(),
    };
  }

  // if (curRes?.['/purchaseNeedMaterialController/applyCompanyID']) {
  //   // 公司权限
  //   return {
  //     params: 'applyCompanyID',
  //     applyCompanyID: getLevelZero(),
  //   };
  // } else if (curRes?.['/purchaseNeedMaterialController/applyDepartmentID']) {
  //   return {
  //     params: 'applyDepartmentID',
  //     applyDepartmentID: getLevelFirst(),
  //   };
  // } else if (curRes?.['/purchaseNeedMaterialController/applyerID']) {
  //   return {
  //     params: 'applyerID',
  //     applyerID: getUserID(),
  //   };
  // }
};
